<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
      <form id="form" action="">
        <input id='ipt' type="text">
        <button id="btn">提交</button>
      </form>
      <script>
        const form = document.querySelector('#form')
        const ipt = document.querySelector('#ipt')
        const btn = document.querySelector('#btn')
        form.onsubmit =function(){
            const userId =ipt.value//获取用户输入内容
            const xhr = new XMLHttpRequest()

            xhr.open('get',`/userPath/${userId}?_=${Date.now()}`,true)//将用户输入内容以path进行传参
            xhr.send()
            xhr.onreadystatechange =function(){
                if(xhr.readyState===4&&xhr.status>=200&&xhr.status<=299){
                    console.log(xhr.responseText)//获取响应体
                }
            }
            return false//给form元素绑定提交事件submit一般我们不用form的提交,所以需要在事件内阻止默认事件
           // 1.e.preventDefault()  2.return false
        }


      </script>
</body>
</html>